package parser;

public class PDelete {
//attribution
	public String tableName;
	public String []leftOPs;
	public String []rightOPs;
	public int []opTypes;
	public String []operators;
//method
	PDelete(String cmd){
		String []sAry;
		String []clauses;
		sAry = cmd.split("\\s+FROM\\s+");
		sAry = sAry[1].split("\\s+WHERE\\s+");
		tableName = sAry[0];
		clauses = sAry[1].split("\\s+AND\\s+");
		leftOPs = new String[clauses.length];
		rightOPs = new String[clauses.length];
		opTypes = new int[clauses.length];
		operators = new String[clauses.length];
		for(int i=0; i<clauses.length; i++){
			if( clauses[i].indexOf(">=")>0){
				operators[i] = new String(">=");
				opTypes[i] = PConstants.NODE_LARGER_EQUAL;
			}
			else if( clauses[i].indexOf("<=")>0){
				operators[i] = new String("<=");
				opTypes[i] = PConstants.NODE_LESS_EQUAL;
			}
			else if( clauses[i].indexOf('=')>0){
				operators[i] = new String("=");
				opTypes[i] = PConstants.NODE_EQUAL;
			}
			else if( clauses[i].indexOf('<')>0){
				operators[i] = new String("<");
				opTypes[i] = PConstants.NODE_LESS;
			}
			else if( clauses[i].indexOf('>')>0){
				operators[i] = new String(">");
				opTypes[i] = PConstants.NODE_LAEGER;
			}
			int pos = clauses[i].indexOf(operators[i]);
			//leftOP
			leftOPs[i] = new String(clauses[i].substring(0,pos));
			//remove blanks at the end
			while(leftOPs[i].endsWith(" "))
			{
				leftOPs[i] = leftOPs[i].substring(0,leftOPs[i].length()-1);
			}
			//rightOP
			if(operators[i].startsWith(">=") || operators[i].startsWith("<="))
				rightOPs[i] = new String (clauses[i].substring(pos+2));
			else rightOPs[i] = new String (clauses[i].substring(pos+1));
			//remove blanks at the start
			while(rightOPs[i].startsWith(" "))
			{
				rightOPs[i] = rightOPs[i].substring(1);
			}
		}
		//System.out.print("");
	}
}
